package bishiqiangxun;

import java.util.Scanner;

//题目买卖股票的最佳时机(一)
public class Test2 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] arr = new int[n];
        for(int i = 0; i < n; i++) {
            arr[i] = in.nextInt();
        }
        int max = 0;
        int min = Integer.MAX_VALUE;
        for(int i = 0; i < n;i++) {
            //先找数组中最小值 再找数组对应下标的值 减去最小值的最大值
            min = Math.min(min,arr[i]);
            max = Math.max(max,arr[i] - min);
        }
        System.out.println(max);
    }
}
